#!/bin/sh

##############################################
# Configuration                              #
##############################################
# path variables
basePath=C:/PAPYRUS
eclipsePath=$basePath/Eclipse/Eclipse3.3.1.1/eclipse
equinoxLauncher=org.eclipse.equinox.launcher_1.0.1.R33x_v20070828.jar
pdeScriptBuilder=org.eclipse.pde.build_3.3.2.R331_v20071019

# build identification
buildType=N
buildId=`date +%Y%m%d` # buildId(date format : YYYYmmDD)
echo "buildID: "$buildId
buildLabel=Papyrus_$buildId
echo $buildLabel
version=1.9.1

# build directory
buildDirectory=$basePath/Build/RCP_RELEASE_1.9.1
binariesDir=$basePath/Resources/Binaries
relengDir=$buildDirectory/com.cea.papyrus.releng
productScriptsDir=$relengDir/scripts/product
updateSiteScriptsDir=$relengDir/scripts/updateSite
installerResourceDir=$buildDirectory/$buildLabel/Papyrus-$version
resultDir=$buildDirectory/result

# map file dir
mapsRoot=$relengDir/maps/

# Repository version : head, release or branch for product plugin (here, org.usinelogicielle.platform) and for maps project!!
# possibilities : head or releases/1.4.5 or branch/1.7.X
tagPath=releases/1.9.1

###############################################################################
# METHODS
###############################################################################

############################################
# Clean Build Space
# clean files comming from previous builds
############################################
echo Cleaning build directories...
rm -vf $buildDirectory/*.properties
rm -vf $buildDirectory/*.xml
rm -vf $buildDirectory/directory.txt

echo Checkout map files and product project ...
# checkout the product project to have the product file to generate the feature corresponding to this project
# /!\ depends if the build is done on the head or branch of svn
# checkout product
svn --force export https://speedy.supelec.fr/Papyrus/svn/Papyrus/core/$tagPath/com.cea.papyrus.product $buildDirectory/plugins/com.cea.papyrus.product

# launch the build
java -jar $eclipsePath/plugins/$equinoxLauncher -application org.eclipse.ant.core.antRunner -buildfile $eclipsePath/plugins/$pdeScriptBuilder/scripts/productBuild/productBuild.xml -Dbuilder=$productScriptsDir -DbuildId=$buildId -DbuildLabel=$buildLabel -DbuildDirectory=$buildDirectory -Dversion=$version -DpluginPath=$binariesDir -DmapsRoot=$mapsRoot

# should unpack the windows version to build the RCP version --> Call ISTool
# unzip win32 file into win32 directory
# rm -rvf $buildDirectory/$buildLabel/installer/win32
# mkdir buildDirectory/$buildLabel/installer/win32
cd $buildDirectory/$buildLabel/
WINZIP32 -min -e -o $buildId-win32.win32.x86.zip   

# copy material useful for building installler for windows in dezip'version
cp -v $relengDir/installer/win32/*.* $installerResourceDir
mkdir $installerResourceDir/resource
cp -v $relengDir/installer/win32/resource/*.* $installerResourceDir/resource/	


# run build script
cd $buildDirectory/$buildLabel/Papyrus-$version
echo "building win32 installer"
Compil32.exe /cc $installerResourceDir/papyrus-$version.iss
echo "Building RCP ok"

# move result to resut Dir
cp -v $buildDirectory/$buildLabel/*.zip $resultDir/
cp -v $buildDirectory/$buildLabel/*.gz $resultDir/
cp -v $buildDirectory/$buildLabel/*.exe $resultDir/
